package cn.smartaccount.demo.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.context.MessageSource;

import java.io.Serializable;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private int code = 200;
    private String message;
    private boolean success;
    private T data;

    public Response() {
    }

    public Response(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 通用成功
     *
     * @param data
     * @return
     */
    public static <T> Response<T> success(T data) {
        Response<T> response = new Response<T>();
        response.data = data;
        response.setMessage("成功");
        response.success = true;
        return response;
    }

    /**
     * 通用成功
     *
     * @return
     */
    public static <T> Response<T> success() {
        Response<T> response = new Response<T>();
        response.data = null;
        response.setMessage("成功");
        response.success = true;
        return response;
    }

    /**
     * 通用成功
     *
     * @param data
     * @return
     */
    public static <T> Response<T> success(T data, String message) {
        Response<T> response = new Response<T>();
        response.data = data;
        response.setMessage(message);
        response.success = true;
        return response;
    }

    /**
     * 通用成功
     *
     * @param data
     * @return
     */
    public static <T> Response<T> success(T data, int code) {
        Response<T> response = new Response<T>();
        response.data = data;
        response.setMessage("成功");
        response.success = true;
        response.setCode(code);
        return response;
    }

    public static <T> Response<T> error(int status, String message) {
        return new Response<T>(status, message);
    }

    private static MessageSource messageSource;


    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
